//
//  EFMyDistributorViewCell.m
//  EnjogFood
//
//  Created by guocheng on 2017/5/17.
//  Copyright © 2017年 wf. All rights reserved.
//

#import "EFMyDistributorViewCell.h"
#import "EFMyDistributorViewItem.h"

@interface EFMyDistributorViewCell()

@property(strong,nonatomic)UIView* headerView;
@property(strong,nonatomic)UILabel* dateLabel;
@property(strong,nonatomic)UILabel* moneyLabel;
@property(strong,nonatomic)UIImageView* moreIV;

@end


@implementation EFMyDistributorViewCell



-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if(self){
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.contentView.backgroundColor = [UIColor clearColor];
        self.backgroundColor = [UIColor whiteColor];
        [self initView];
    }
    return self;
}

-(void)setObject:(EFMyDistributorViewItem *)item{
    [self.dateLabel setText:item.date];
    NSString* str = NSStringF(@"%获得佣金￥%@",item.commission);
    if([item.commission intValue] < 0){
        str = NSStringF(@"%花费佣金￥%@",item.commission);
    }
    NSMutableAttributedString * strIntro = [[NSMutableAttributedString alloc]initWithString:str];
    NSRange range = NSMakeRange([[strIntro string] rangeOfString:@"￥"].location, ([strIntro string].length - [[strIntro string] rangeOfString:@"￥"].location));
    [strIntro addAttribute:NSForegroundColorAttributeName value:RGBCOLOR(0x60BA45) range:range];
    [self.moneyLabel setAttributedText:strIntro];
    
    [self.moneyLabel sizeToFit];
    self.moneyLabel.left = kScreenWidth -  self.moneyLabel.width - self.moreIV.width - 27;
    
    if(item.hide){ 
        _moreIV.transform=CGAffineTransformMakeRotation(M_PI*0);
    }else{
        _moreIV.transform=CGAffineTransformMakeRotation(M_PI*3.5);
    }
    
}

-(void)initView{
    [self.contentView setBackgroundColor:RGBCOLOR(0xF4F4F4)];
    [self.contentView addSubview:self.headerView];
    [self.contentView addSubview:self.dateLabel];
    [self.contentView addSubview:self.moneyLabel];
    [self.contentView addSubview:self.moreIV];
}


-(void)layoutSubviews{
    
    self.dateLabel.left = 20;
    self.dateLabel.top = self.headerView.bottom + 12;
    
    self.moreIV.left = kScreenWidth - self.moreIV.width - 20;
    self.moreIV.top = self.headerView.bottom + 12;
    
    self.moneyLabel.top = self.headerView.bottom + 12;
    
}


-(UILabel *)dateLabel{
    if(_dateLabel == NULL){
        _dateLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 94, 21)];
        _dateLabel.textColor = kBlack333;
        _dateLabel.font = [UIFont systemFontOfSize:15];
    }
    return _dateLabel;
}

-(UILabel *)moneyLabel{
    if(_moneyLabel == NULL){
        _moneyLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 0, 21)];
        _moneyLabel.textColor =  kBlack333;
        _moneyLabel.font = [UIFont systemFontOfSize:15];
    }
    return _moneyLabel;
}

-(UIImageView *)moreIV{
    if(_moreIV == NULL){
        _moreIV = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 20, 20)];
        [_moreIV setImage:IMG(@"putaway_icon_default")];
       
        UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(moreIVTapAction)];
        [self.moreIV addGestureRecognizer:tapGesture];
        self.moreIV.userInteractionEnabled = YES;
    }
    return _moreIV;
}

-(UIView *)headerView{
    if(_headerView == NULL){
        _headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 10)];
        _headerView.backgroundColor = [UIColor whiteColor];
    }
    return _headerView;
}


-(void)moreIVTapAction{
    if (self.more != nil) {
        self.more();
    }
}





@end
